
*** This do file generates figure B8 for the minimum wage precommitment paper.

*** Stacked event studies using the year of first statutory increase as the first treatment year combining large and small increasers together
*** Prime age individuals
* If needed change global path to point to directory where files are stored on your computer
*global path "I:/DataSets5/Duncan/Dropbox/Recent Minimum Wage Changes/2020.12 NBER Update/JOLE Precommittment Replication"
global dtadir "$path/Data"
global tabdir "$path/Tables"
global figdir "$path/Figures"
global estdir "$path/Estimates"
global logdir "$path/Logfiles"

*****************************************************************************************************
************		                     2. Program for Stacked Dataset				     ************
*****************************************************************************************************

capture program drop gen_dataset 
program define gen_dataset 

	** syntax
	syntax, treatyear(varname) cohort(real)
	

	use "${path}/Data/ACSEventStudiesData.dta", clear
	
	keep if `treatyear' == `cohort' | `treatyear' ==.
	gen treat_stacked = 0
	replace treat_stacked = 1 if `treatyear' !=. /* treatment var is any cohort year */
	gen cohort = `cohort'  /* label reform */ 

	** recode years to be in event time 
	qui gen t = year - `cohort' + 1 
	qui replace t = -3 if inrange(t,-10,-3) 
	qui replace t = 4 if inrange(t,4,10) 
	
	* Generate sample indicators
	gen lowskilled = 0
	replace lowskilled = 1 if inrange(age,16,25) & dropout == 1

	gen young = 0
	replace young = 1 if inrange(age,16,21)

	gen primeage = 0
	replace primeage = 1 if inrange(age,26,54)

	gen highskill = 0
	replace highskill = 1 if  inrange(age,26,54) & educ > 6 
	
end

*****************************************************************************************************
************		                     3. Program for Event Studies		************
*****************************************************************************************************


capture program drop did_stacked
program define did_stacked

	*------------------------ 3.1 Syntax --------------------------

	syntax varlist(min=2 max=2), [xvar(string) pretrend(real 0) otherlab(string) panel(string)]

	local outcome `1'
	local sample = subinstr("`2'",",","",.)
	
	*------------------------ 3.2 Set Up --------------------------

	est clear
	
	* event time defintion and range
	cap drop tvar
	gen tvar = t + 4

	* generate sample tag
	cap drop sample
	gen sample = inrange(tvar, 1, 8) & `sample' == 1
	keep if sample == 1
	local ref = 0 + 4

	*------------------------ 3.3 Event Study --------------------------
	
	* Set controls
	if "`otherlab'" == "nocontrols" {
	    local xvar
		local controlslabel `"No Controls"'
	}
	
	else if "`otherlab'" == "basecontrols" {
	    local xvar lnPersonalIncome HPI
		local controlslabel `"Sparse Controls"'
	}
	
	else if "`otherlab'" == "richcontrols" {
	    local xvar i.age i.educ lnPersonalIncome HPI D3lnPersonalIncome D3HPI
		local controlslabel `"Rich Controls"'
	}
	
	else {
	    local xvar
		local controlslabel `"None"'
	}
	
	* Set sample label
	if "`sample'" == "lowskilled" {
		local samplabel  `"Low-Skilled"'
	}
	
	else if "`sample'" == "young" {
		local samplabel `"Young"'
	}
	
	else if "`sample'"== "primeage" {
		local samplabel `"Prime Age"'
	}
	else if "`sample'" == "highskill" {
		local samplabel `"Prime Age Higher-Skilled"'
	}
	else {
		local samplabel `"None"'
	}
	
	* Stacked Event Study Regression
	eststo: reghdfe `outcome' b`ref'.tvar##i.treat_stacked `xvar' [pw=cmpwgt] if sample == 1, absorb(statefip year cohort##statefip) cluster(statefip)
	
	* Save coefficients
		* create matrix
		mat est = J( 8 , 4, .)
						
		* fill matrix with values of t, point estimates, and CI
		local n = 1
		foreach t of numlist -3/4 {
			* tnorm
			local tnorm = `t' + 4
			* event time
			mat est[`n',1]  = `t' 
			* normalized coefficient
			mat est[`n',2] =  _b[`tnorm'.tvar#1.treat_stacked]
			* lower CI
			mat est[`n',3] = _b[`tnorm'.tvar#1.treat_stacked] + invnorm(0.025)*_se[`tnorm'.tvar#1.treat_stacked]
			* upper CI
			mat est[`n',4] = _b[`tnorm'.tvar#1.treat_stacked] + invnorm(0.975)*_se[`tnorm'.tvar#1.treat_stacked]
			local n = `n' + 1
		}

		* store coefficients to dataset
		cap drop est?
		svmat est
	*------------------------ 3.5 Plot  --------------------------

	graph twoway (scatter est2 est1, msymbol(circle) msize(medium) mc(black) lc(black)) ///
				(rspike est3 est4 est1, color(black) m(i) ///
					yline(0, lcolor(black)) ///
					ylabel(-.075 "-.075" -0.05 "-.050" -0.025 "-.025" 0 "0" .025 ".025", labsize(small) gmin gmax) ///
					xlabel(-3 "-3+" -2 "-2" -1 "-1" 0 "0" 1 "1" 2 "2" 3 "3" 4 "4+", labsize(small)) xscale(range(-3 4)) ///
					xtitle("") ytitle("") bgcolor(white) graphregion(color(white)) ///
					title("Panel `panel': `samplabel' with `controlslabel'", size(medsmall) color(black)) ///
					legend(order(1 "All Statutory Increasers" 2 "Lower 95% confidence limit/Upper 95% confidence limit") rows(1) region(lstyle(none)) size(small) symxsize(small) symysize(small)) /// 					
					name("`outcome'_`sample'_`otherlab'", replace))

end
				

*****************************************************************************************************
************				          4. Graph				*************
*****************************************************************************************************
#delimit cr

cap log close 

* start log file 
log using "$logdir/stacked-event-studies-all-increasers-prime-age-3-panel-drop-indexers.log", replace


* Load data
use "${path}/Data/ACSEventStudiesData.dta", clear

tab legimpyear1

* -------------------------- 2.1 Create Event Study Dataset for Increase --------------------------- 

tempfile stacked

* 2013
	gen_dataset, treatyear(legimpyear1) cohort(2013)
	qui save `stacked', replace
* 2014
	gen_dataset, treatyear(legimpyear1) cohort(2014)
	qui append using `stacked'
	qui save `stacked', replace 
* 2015
	gen_dataset, treatyear(legimpyear1) cohort(2015)
	qui append using `stacked'
	qui save `stacked', replace
* 2016
	gen_dataset, treatyear(legimpyear1) cohort(2016)
	qui append using `stacked'
	qui save `stacked', replace 
 * 2017
	gen_dataset, treatyear(legimpyear1) cohort(2017)
	qui append using `stacked'
	qui save `stacked', replace 
* 2019
	gen_dataset,  treatyear(legimpyear1) cohort(2019)
	qui append using `stacked'
	qui save `stacked', replace

* Drop all indexer states
drop if indexer == 1

	
* -------------------------- 2.2 Graph --------------------------- 

est clear

* primeage
	did_stacked employed primeage, otherlab(nocontrols) panel(A)
	did_stacked employed primeage, otherlab(basecontrols) panel(B)
	did_stacked employed primeage, otherlab(richcontrols) panel(C)


* Combine graphs to make a 3-panel figure
set graph on
graph dir // These named graphs are now in memory

*
grstyle init
grstyle color background white
grstyle graphsize x 20
grstyle graphsize y 11
grstyle set legend, nobox


* Combined employment graph prime-age
grc1leg2 employed_primeage_nocontrols employed_primeage_basecontrols employed_primeage_richcontrols, ///
	l1("Change", size(medsmall)) b1("Event Time", size(medsmall)) ring(2) xsize(20) ysize(11) margins(tiny) ///
	legendfrom(employed_primeage_basecontrols) lsize(medsmall) graphregion(color(white)) rows(2)
graph save "$figdir/stacked-event-studies-primeage-all-increases-drop-all-indexers.gph", replace
graph export "$figdir/stacked-event-studies-primeage-all-increases-drop-all-indexers.pdf", as(pdf) replace



* 	employed_highskill_nocontrols employed_highskill_basecontrols employed_highskill_richcontrols,  ///
